const { ccclass, property } = cc._decorator;

@ccclass
export default class Record extends cc.Component {

    @property(cc.ScrollView)
    scrollView: cc.ScrollView = null

    @property(cc.Node)
    item: cc.Node = null

    onLoad() {
    }

    onEnable() {
        this.scrollView.content.removeAllChildren()
        let recordData = ut.GetLocalStorage('wlffl-record') || []
        recordData.sort((a, b) => { return a.consume - b.consume })
        for (let i = 0; i < recordData.length; i++) {
            let d = recordData[i]
            let cloneItem: any = cc.instantiate(this.item)
            cloneItem.PathChild('frame').active = i % 2 == 0
            if (i < 5) {
                ut.SetSpriteFrame(`image/record/icon_no${i + 1}`, cloneItem.PathChild('rankImg', cc.Sprite))
            } else {
                cloneItem.PathChild('rank', cc.Label).string = `${i + 1}`
            }
            cloneItem.PathChild('consume', cc.Label).string = `${d.consume}秒`
            cloneItem.PathChild('date', cc.Label).string = `${d.date}`
            cloneItem.parent = this.scrollView.content
        }
    }

    onDisable() {
    }

    btnReturn() {
        this.node.active = false
    }
}
